package org.chengyi.model_shop.controller;

import org.chengyi.model_shop.entity.Category;
import org.chengyi.model_shop.entity.CategoryDetail;
import org.chengyi.model_shop.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @GetMapping("/categories")
    public List<CategoryDetail> getCategoryList()
    {
        return categoryService.getCategoryList();
    }
    @PostMapping("/categories")
    public String addCategory(@RequestBody Category  category)
    {
        return categoryService.addCategory(category);
    }
    @DeleteMapping("/categories")
    public String deleteCategory(@RequestParam Integer categoryId){
        return categoryService.deleteCategory(categoryId);
    }
    @PutMapping("/categories")
    public String updateCategory(@RequestBody Category category){
        return categoryService.updateCategory(category);
    }
}
